Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: build merkl airdrop csv based on user pool shares #1575

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

gosuto-inzasheru
Copy link
Collaborator

closes #1563

Comment on lines +69 to +80
def consolidate_shares(df):
consolidated = pd.DataFrame()
for block in df.columns:
# calculate the percentage of the pool each user owns
consolidated[block] = df[block] / df[block].sum()
# weigh it by the total pool size of that block
consolidated[block] *= df.sum()[block]
# sum the weighted percentages per user
consolidated["total"] = consolidated.sum(axis=1)
# divide the weighted percentages by the sum of all weights
consolidated["total"] = consolidated["total"] / df.sum().sum()
return consolidated
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Xeonus or @jalbrekt85 it would be good if one of you has time to draft review this function. it is at the core of this whole feature/pr

if we agree on this piece of logic, then next step for me will be to add multi pool support

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mathematically, looks correct to me.
I see 2 edge cases:

  1. might end up with division by zero if df[block].sum is 0
  2. accumulate of floating point precision issues for small balances but that is a general limiation of data fetching

I would rewrite it to something like this so you don't do the same block sum operation

def consolidate_shares(df):
    if df.empty:
        raise ValueError("Empty dataframe provided")
    
    # Pre-calculate sums to avoid redundant computation
    block_sums = df.sum()
    total_sum = block_sums.sum()
    
    if total_sum == 0:
        raise ValueError("No shares found in any block")
    
    consolidated = pd.DataFrame()
    for block in df.columns:
        block_sum = block_sums[block]
        if block_sum == 0:
            continue
        
        # Calculate weighted ownership for this block
        consolidated[block] = (df[block] / block_sum) * block_sum
    
    # Calculate final weighted average
    consolidated["total"] = consolidated.sum(axis=1) / total_sum
    return consolidated

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Retroactive Morpho reward Distribution automation
2 participants